package sort;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        int[] nums = new int[]{2, 34, 56, 43, 99, 6, 7, 4, 3, 5, 6, 7, 65, 3, 2};
        bubbleSort(nums);
        System.out.println(Arrays.toString(nums));

    }

    public static void bubbleSort(int[] nums) {
        if (nums.length < 2 || nums == null) {
            return;
        }

        for(int i = nums.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (nums[j] > nums[j + 1]) {
                    swap(nums, j, j + 1);
                }
            }
        }
    }

    private static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
